<!--
 * Created by PhpStorm.
 * User: jackhhy
 * Date: 2019/7/11-10:59
 * Link: https://gitee.com/luckygyl/lucky_admin
 * FileName: add_album.html
 *-->

{include file="public/open_head" /}
<link rel="stylesheet" href="{__FRAME_PATH}css/inputTags.css">
<div class="ok-body">

    <div class="layui-fluid">
        <div class="layui-card">
            <!-- <div class="layui-card-header"></div>-->

            <div class="layui-card-body" style="padding: 15px;">
                <div class="layui-form">

                    {:token()}
                    <?php echo Form::Input('text','name','','相册名称','请输入相册名称','required');?>

                    <?php echo Form::Textarea('describe','','相册描述','相册的一些描述简介','请输入相册描述','required');?>

                    <div class="layui-form-item">

                        <?php echo Form::Radio('is_show',1,'是否显示',array('2'=>'否','1'=>'是'),'','','inline',2);?>

                        <?php echo Form::Radio('is_top',0,'是否置顶',array('0'=>'否','1'=>'是'),'','','inline',2);?>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">相册标签：</label>
                        <div class="layui-input-block">
                            <div class="tags">
                                <input type="text"  id="inTag" placeholder="回车生成标签" class="inputTag" autocomplete="off">
                                <input type="hidden" id="val" name="tags">
                            </div>
                        </div>
                    </div>

                    <?php echo Form::Radio('is_open',0,'是否加密',array(0=>'否',1=>'是'),'','radio');?>

                    <?php echo Form::Input('password','pass','','加密密码','请输入相册的加密密码','','加密了的相册，访问时候需要输入加密的密码！','','block','','password','','display:none;');?>

                    <?php echo Form::Upthumb('img','','相册封面','封面地址','required','上传封面');?>

                    <?php echo Form::Submit('add','立即提交');?>


                </div>
            </div>
        </div>
    </div>


</div>




<script>
    layui.config({
        base: "{__FRAME_PATH}js/"
    }).extend({
        inputTags: 'inputTags'
    });
    layui.use(['element', 'form', 'jquery','upload','inputTags'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var upload=layui.upload;
        var inputTags=layui.inputTags;

        inputTags.render({
            elem:'#inTag',
            content: [],
            aldaBtn: false,
            in_id: 'val',
        });

        //图片上传
        upload.render({
            elem:'#LAY_avatarUpload'
            ,url: "{:url('admin/common/UpThumbImg')}" //头像上传地址
            ,accept: 'images' //视频
            ,acceptMime: 'image/*'
            ,size: 1024*9
           // ,data:{width:450,height:300}
            ,before:function (res) {
                loading = layer.load(2, {
                    shade: [0.2, '#000'] //0.2透明度的白色背景
                });
            }
            ,done: function(data){
                layer.close(loading);
                if (data.code==1){
                    layer.msg(data.msg, {icon: 1, time: 1000},function () {
                        $("#demo1").attr("src",data.path);
                        $("#LAY_avatarSrc").val(data.path);
                    });
                } else {
                    layer.msg(data.msg, {icon: 5, time: 1000});
                }
            }
            ,error:function (red) {
                layer.close(loading);
                layer.msg("网络错误", {icon: 5, time: 1500});
            }
        });


        /**
         *
         */
        form.on("radio(radio)",function (data) {

            //console.log(data);
            if (parseInt(data.value)==1){
                $(".password").show(0);
            } else {
                $(".password").hide(0);
            }
        });


        /**
         * 提交表单数据
         */
        form.on('submit(add)', function (data) {
            $.ajax({
                url:"{:url('album/AddAlbum')}",
                type:'post',
                data:data.field,
                error: function(error) {
                    layer.msg("服务器错误或超时");
                    return false;
                },
                beforeSend:function(){
                    layer.load(2);
                },
                success:function(data)
                {
                    if (data.code==1) {
                        layer.msg(data.msg,{icon: 1, time: 1500,shade:0.3, anim: 4},function () {
                            parent.location.reload(); //刷新父页面
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });

                    }else{
                        layer.msg(data.msg,{icon:15,time:1500,shade:0.3,anim:4});
                    }
                },
                complete:function(){
                    layer.closeAll('loading');
                }
            });
            return false;
        });
    })
</script>


</body>
</html>
